package cn.edu.sjtu.software.sjtucontacts.activity;


import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

public class ContactProvider extends ContentProvider {

	private UriMatcher mat=null;
	private final static int AUTH=1;
	
	private PullService pullService = null;
	
	private static final String AUTHORITY = "sjtu.contact";
	
	
	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		
		switch (mat.match(uri)) {
			case AUTH:
			return "vnd.android.cursor.dir/";//?????????????
			//case CONTACT_ID:
		//	return "vnd.android.cursor.item/vnd.wongxming.gcontacts";
			default:
			throw new IllegalArgumentException("Unsupported URI: " + uri);
		}
		
	}

	@Override
	public Uri insert(Uri uri, ContentValues initialValues) {
		// TODO Auto-generated method stub
		if(mat.match(uri)!=AUTH){
			throw new IllegalArgumentException("Unknown URI " + uri);
		}
		
		ContentValues values;
		if (initialValues != null) {
			values = new ContentValues(initialValues);
			Log.e("Provider "+"insert","initialValues is not null");
		} else {
			values = new ContentValues();
		}
		
		
		
		return null;
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		Context c=this.getContext();
		mat=new UriMatcher(UriMatcher.NO_MATCH);
		mat.addURI(AUTHORITY, "notes", AUTH);
		pullService = new PullService();
		return (pullService == null)? false : true;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
